package com.cloud.poetry.base.util;

import com.cloud.poetry.base.entity.User;
import com.cloud.poetry.core.constant.PoetryConstant;
import com.cloud.poetry.core.util.CommonUtil;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author mengxj
 */
public class BaseUtil {

    /**
     * 获取当前人信息
     * @return 当前人信息
     */
    public static User getUser(){
        return (User) CommonUtil.getRequest().getSession().getAttribute(PoetryConstant.CUR_USER);
    }

    /**
     * 将当前登陆人存入session
     * @param user 当前登陆人
     */
    public static void saveUser(User user){
        CommonUtil.getRequest().getSession().setAttribute(PoetryConstant.CUR_USER, user);
    }

    /**
     * 退出登录
     */
    public static void logout(){
        HttpSession session = CommonUtil.getRequest().getSession();
        session.removeAttribute(PoetryConstant.CUR_USER);
    }
}
